import smtplib
import random
import hashlib

from email.mime.text import MIMEText
from email.header import Header

def md5_pwd(pwd):
    pwd = str(pwd)
    md5_obj = hashlib.md5('shujia'.encode('UTF-8'))
    md5_obj.update(pwd.encode('UTF-8'))
    return md5_obj.hexdigest()

def send_email(msg_to, send_info):
    msg_from = '1165872335@qq.com'  # 发送方邮箱
    passwd = 'owbciardnivafija'  # 填入发送方邮箱的授权码(填入自己的授权码，相当于邮箱密码)
    # msg_to = ['','','']

    subject = "张成阳婚恋介绍所邮件验证码"  # 主题
    # 生成一个MIMEText对象（还有一些其它参数）
    msg = MIMEText(send_info)
    # 放入邮件主题
    msg['Subject'] = subject
    # 也可以这样传参
    # msg['Subject'] = Header(subject, 'utf-8')
    # 放入发件人
    msg['From'] = msg_from
    # 放入收件人
    # 通过ssl方式发送，服务器地址，端口
    s = smtplib.SMTP_SSL("smtp.qq.com", 465)
    # 登录到邮箱
    s.login(msg_from, passwd)
    # 发送邮件：发送方，收件方，要发送的消息
    s.sendmail(msg_from, msg_to, msg.as_string())
    print('成功')

def rand_yzm():
    return random.randint(100000,999999)